package com.it2297.view;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JScrollPane;

import com.it2297.controller.NeedyController;
import com.it2297.model.Needy;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;


public class NeedySearchView extends JPanel {
	private final NeedyController controller = new NeedyController(this);
	
	private final JTextField searchTxt = new JTextField();
	public JTextField getSearchTxt() {
		return searchTxt;
	}
	private final JLabel lblNewLabel = new JLabel("Search By Name");
	private final JButton btnSearch = new JButton("Search");
	private final JScrollPane scrollPane = new JScrollPane();
	private final JPanel panel = new JPanel();

	/**
	 * Create the panel.
	 */
	public NeedySearchView() {
		searchTxt.setBounds(262, 51, 174, 37);
		searchTxt.setColumns(10);
		
		this.setSize(741,555);

		initGUI();
	}
	private void initGUI() {
		setLayout(null);
		
		add(searchTxt);
		lblNewLabel.setFont(new Font("Arial", Font.PLAIN, 19));
		lblNewLabel.setBounds(102, 48, 150, 37);
		
		add(lblNewLabel);
		btnSearch.setFont(new Font("Arial", Font.PLAIN, 19));
		
		btnSearch.setBounds(467, 48, 103, 37);
		
		add(btnSearch);
		scrollPane.setBounds(102, 96, 600, 419);
		
		add(scrollPane);
		scrollPane.setViewportView(panel);
		
		btnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				if(searchTxt.getText().isEmpty()){
					JOptionPane.showMessageDialog(null,"Please Enter Name");  
				}
				else
					   controller.generateList();
				JOptionPane.showMessageDialog(null,"Successfully searched"); 
				
				/*
				if(!Needy.IsNameExist(searchTxt.getText())){
					
				        controller.generateList();
						JOptionPane.showMessageDialog(null, "successfully searched");
						}
				else{
					
					JOptionPane.showMessageDialog(null, "No matches Name found");
					
				}
				*/
		
					
			}
				
			
		});
		
		
		
		
		
	}
	public JPanel getPanel() {
		return panel;
	}
	public JScrollPane getScrollPane() {
		return scrollPane;
	}
}
